<template>
  <div class="pat_info">
    <div class="grid_tit">
      <div class="flex flex-row align-center justify-between pad-b-6 mar-t-10">
        <div class="mar-l-3 flex flex-row align-center">
          <span class="font-bold">申请单信息</span>
          <el-button class="mar-l-10 conditionSearchBtn" size="mini" v-permission="'YJYY10007003'" @click="appointResultSearch">预约情况查询</el-button>
        </div>
        <div class="ky-fr flex flex-row align-center mar-l-5">
          <!-- <span>{{rowCurr.emergency+'-'+rowCurr.emergencyLabel}}</span> -->
          <div
            class="mar-r-5"
            style="cursor: pointer;width: 100px;"
            v-permission="'YJYY10008065'"
            title="修改检查设备"
          >
            <el-select v-model="currentModality" placeholder="检查设备" size="mini" @change="handleModalityChange">
              <el-option
                v-for="(item,index) in modalitylist"
                :key="index"
                :label="item"
                :value="item">
              </el-option>
            </el-select>
          </div>
          <el-tag
            v-if="isConfigBedside && (rowCurr && rowCurr.visit ? getSource('','',rowCurr.visit.patientSource) : getSource('','',rowCurr && rowCurr.patientSource)) == '住院' && rowCurr.isOverBed != null && rowCurr.isOverBed != undefined"
            size="mini"
          >{{rowCurr.isOverBed ? '床旁' : '非床旁'}}</el-tag>
          <div
            v-permission="'YJYY10008064'"
            @click="editEmergency(rowCurr.emergencylabel)"
            style="cursor: pointer;margin-left: 5px;"
            title="修改急诊标志"
          >
            <el-tag
              v-if="rowCurr.emergency > 0 && ((isSetEmergencyValue && [1, 2, 3, 4].includes(rowCurr.emergency)) || (!isSetEmergencyValue && [1, 14, 15, 16].includes(rowCurr.emergency)))"
              size="mini"
              type="danger"
            >{{rowCurr.emergencylabel}}</el-tag>
            <span v-else>
              {{rowCurr.emergencylabel}}
            </span>
            <i class="mar-l-3 el-icon-edit" style="cursor: pointer;"></i>
          </div>
          <!-- <div
            v-if="!$hasPermission(['YJYY10008064'])"
            title="修改急诊标志"
          >
            <el-tag
              v-if="rowCurr.emergency > 0 && ((isSetEmergencyValue && [1, 2, 3, 4].includes(rowCurr.emergency)) || (!isSetEmergencyValue && [1, 14, 15, 16].includes(rowCurr.emergency)))"
              size="mini"
              effect="dark"
              type="danger"
            >{{rowCurr.emergencylabel}}</el-tag>
            <span v-else>
              {{rowCurr.emergencylabel}}
            </span>
          </div> -->
          <!-- <el-tag
            v-if="parseInt(rowCurr.emergency) > 0 && isShowEmergencyLimit"
            size="mini"
            effect="dark"
          >{{rowCurr.emergencyInfo}}</el-tag> -->
          <div class="mar-l-5">
            <el-tag
              class="mar-l-5"
              v-if="rowCurr.patientName && !isSetEmergencyValue && [1, 14, 15, 16].indexOf(rowCurr.emergency) > -1"
              :title="rowCurr.emergencyInfo"
              size="mini"
              :type="!isSetEmergencyValue && parseInt(rowCurr.emergency) ? 'danger':'warn'"
            >{{rowCurr.patientName}}</el-tag>
            <el-tag
              class="mar-l-5"
              v-else-if="rowCurr.patientName && isSetEmergencyValue && [1, 2, 3, 4].indexOf(rowCurr.emergency) > -1"
              :title="rowCurr.emergencyInfo"
              size="mini"
              :type="isSetEmergencyValue && [1, 2, 3, 4].indexOf(rowCurr.emergency) > -1 ? 'danger':'warn'"
            >{{rowCurr.patientName}}</el-tag>
            <el-tag
              class="mar-l-5"
              v-else-if="rowCurr.patientName"
              size="mini"
              type="warn"
            >{{rowCurr.patientName}}</el-tag>
            <span v-else>{{rowCurr.patientName}}</span>
            <span>{{rowCurr.genderTxt}} {{rowCurr.patAgeTxt}}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="pat_info_item mar-t-6">
      <AppInfoItem label="PID" v-if="mipVisible == false" :txt="rowCurr.patientId" style="width: 50%"/>
      <AppInfoItem label="PID" v-else :txt="rowCurr.masterPatientIndexId" style="width: 50%"/>
      <AppInfoItem label="病人类型" style="width: 50%">
        <span>{{rowCurr && rowCurr.visit ? getSource('','',rowCurr.visit.patientSource) : getSource('','',rowCurr && rowCurr.patientSource)}}</span>
      </AppInfoItem>
      <AppInfoItem label="出生日期" :txt="rowCurr.birthDate" style="width: 50%"/>
      <AppInfoItem label="检查备注" v-if="isSendParam" :txt="rowCurr.remarkInfo" style="width: 50%" item-txt-color="#f00">
        <i class="el-icon-edit" @click="editRemarkInfo(rowCurr.remarkInfo)" title="修改备注信息" style="cursor: pointer;color:#000" v-if="isSetRemarkInfo"></i>
      </AppInfoItem>
      <AppInfoItem label="联系方式" v-if="!isSendParam" :txt="rowCurr.patientPhone" style="width: 50%"><i class="el-icon-edit" @click="editPhone(rowCurr.patientPhone)" title="修改联系方式" style="cursor: pointer;"></i></AppInfoItem>
      <!-- 新增地址信息 -->
      <AppInfoItem label="地址" :txt="rowCurr.address" style="width: 50%;"/>
      <AppInfoItem label="优惠类型" :txt="rowCurr.feeType" style="width: 50%"/>
      <AppInfoItem label="申请医生" :txt="rowCurr.applyDoctor" style="width: 50%"/>
      <AppInfoItem label="申请科室" :txt="rowCurr.applyDepartment" style="width: 50%"/>
      <AppInfoItem label="申请时间" :txt="rowCurr.applyDateTime" style="width: 50%"/>
      <AppInfoItem label="床号" :txt="rowCurr.bedNo" style="width: 50%"/>
      <AppInfoItem label="检查项目" :txt="rowCurr.examItemName" style="width: 50%"/>
      <AppInfoItem label="检查部位" :txt="rowCurr.examPart" style="width: 50%"/>
      <AppInfoItem label="优先级" style="width: 100%">
        <!-- <el-tag v-if="rowCurr.emergency > 0 && rowCurr.emergencylabel !='普通' && rowCurr.emergencylabel" size="mini" effect="dark" :type="rowCurr.emergency && rowCurr.emergencylabel !='普通' ? 'danger': ''">{{rowCurr.grade}}</el-tag> -->
        <!-- <el-tag v-if="rowCurr.emergency > 0 && rowCurr.emergencylabel && ['中', '普通', '非急诊'].indexOf(rowCurr.emergencylabel) === -1" size="mini" effect="dark" type="danger">{{rowCurr.grade}}</el-tag> -->
        <el-tag v-if="['急诊', 'VIP'].indexOf(rowCurr.grade) > -1" size="mini" type="danger">{{rowCurr.grade}}</el-tag>
        <span v-else>{{rowCurr.grade || ''}}</span>
        <i class="el-icon-edit" @click="editLevel(rowCurr.grade)" title="修改优先级" style="cursor: pointer;"></i>
        <template v-if="applyInfoHospital =='hhsyy'">
          <el-checkbox class="mar-l-20" v-model="rowCurr.isJZ" @change="handleJZChange">急诊</el-checkbox>
        </template>
        <template v-else>
          <el-checkbox class="mar-l-20" v-permission="'YJYY10007001'" v-model="rowCurr.isJZ" @change="handleJZChange">急诊</el-checkbox>
        </template>
        <el-checkbox class="mar-l-20" v-model="rowCurr.isVIP" label="VIP" @change="handleVIPChange">VIP</el-checkbox>
        <el-checkbox class="mar-l-20" v-model="rowCurr.isOverBed" v-if="isConfigBedside && (rowCurr && rowCurr.visit ? getSource('','',rowCurr.visit.patientSource) : getSource('','',rowCurr && rowCurr.patientSource)) == '住院' && !rowCurr.isBed" label="床旁" @change="handleBedSideChange">床旁</el-checkbox>
      </AppInfoItem>
      <AppInfoItem v-if="['CT','XRAY','MR','DR','MG', 'RF'].indexOf(rowCurr.examClass) > -1 && isToPrint" label="胶片打印" style="width: 50%">
        <el-checkbox style="margin-left:0px;" v-model="checkcs" :true-label="'打胶片'" :false-label="''" @change="handleCheckcsChange">打胶片</el-checkbox>
      </AppInfoItem>
      <AppInfoItem label="保密级别" style="width: 50%">
        <el-tag v-if="rowCurr.privacyLevel" size="mini" type="danger">{{rowCurr.privacyLevel}}</el-tag>
        <span v-else>{{rowCurr.privacyLevel || ''}}</span>
        <i class="el-icon-edit" @click="editPrivacyLevel(rowCurr.privacyLevel || rowCurr.PrivacyLevel)" title="修改保密级别" style="cursor: pointer;" v-permission="'YJYY10008051'"></i>
      </AppInfoItem>
      <!-- 暂用附二 -->
      <AppInfoItem label="胃镜药物" item-label-color="#00C0EF" style="width: 50%" v-if="['内窥镜', 'ES'].indexOf(rowCurr.dep) > -1">
        <span>{{rowCurr.gastroscopicMedicine || ''}}</span>
      </AppInfoItem>
      <AppInfoItem label="药物" item-label-color="#00C0EF" style="width: 50%" v-if="['内窥镜', 'ES'].indexOf(rowCurr.dep) > -1">
        <span>{{rowCurr.material || ''}}</span>
      </AppInfoItem>
      <!-- <AppInfoItem label="保密级别" style="width: 50%" v-permission="'YJYY10008051'">
        <el-select size="mini" ref="examClass" v-model="rowCurr.privacyLevel" filterable style="width:120px;" @change="changePrivacyLevel" clearable>
          <el-option
            v-for="(item, index) in privacyLevelList"
            :key="index"
            :value="item.value"
            :label="item.label"
          ></el-option>
        </el-select>
      </AppInfoItem> -->
      <AppInfoItem v-show="false" label="丙肝" txt="" style="width: 50%" v-if="['内窥镜', 'ES'].includes(rowCurr.dep)">
        <el-select :class="isHcv ? 'special-color' : ''" size="mini" v-model="defaultChoose.hcv" filterable style="width:120px;" clearable @change="changeHCV">
          <el-option
            v-for="(item, index) in hBSagOptions"
            :key="index"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
      </AppInfoItem>
      <AppInfoItem v-show="false" label="RPR" txt="" style="width: 50%" v-if="['内窥镜', 'ES'].includes(rowCurr.dep)">
        <el-select :class="isRpr ? 'special-color' : ''" size="mini" v-model="defaultChoose.rpr" filterable style="width:120px;" clearable @change="changeRPR">
          <el-option
            v-for="(item, index) in hBSagOptions"
            :key="index"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
      </AppInfoItem>
      <AppInfoItem v-show="false" label="HIV" txt="" style="width: 50%" v-if="['内窥镜', 'ES'].includes(rowCurr.dep)">
        <el-select :class="isHiv ? 'special-color' : ''" size="mini" v-model="defaultChoose.hiv" filterable style="width:120px;" clearable @change="changeHIV">
          <el-option
            v-for="(item, index) in hBSagOptions"
            :key="index"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
      </AppInfoItem>
      <AppInfoItem v-show="false" label="HBsAg" txt="" style="width: 50%" v-if="['内窥镜', 'ES'].includes(rowCurr.dep)">
        <el-select :class="isHbsag ? 'special-color' : ''" size="mini" v-model="defaultChoose.hbsag" filterable style="width:120px;" clearable @change="changeHBsAg">
          <el-option
            v-for="(item, index) in hBSagOptions"
            :key="index"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
      </AppInfoItem>
      <AppInfoItem v-show="false" label="PRG" txt="" style="width: 50%" v-if="['内窥镜', 'ES'].includes(rowCurr.dep)">
        <el-select :class="isPRG ? 'special-color' : ''" size="mini" v-model="defaultChoose.PRG" filterable style="width:120px;" clearable @change="changePRG">
          <el-option
            v-for="(item, index) in hBSagOptions"
            :key="index"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
      </AppInfoItem>
      <AppInfoItem v-show="false" label="SCR" txt="" style="width: 50%" v-if="['内窥镜', 'ES'].includes(rowCurr.dep)">
        <el-select :class="isSCR ? 'special-color' : ''" size="mini" v-model="defaultChoose.SCR" filterable style="width:120px;" clearable @change="changeSCR">
          <el-option
            v-for="(item, index) in hBSagOptions"
            :key="index"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
      </AppInfoItem>
      <!-- <AppInfoItem label="临床诊断" :txt="rowCurr.clinicdiagnosis" style="width: 100%;" min-height="60px"/> -->
      <AppInfoItem label="主诉" :txt="rowCurr.chiefComplaint" style="width: 100%;" min-height="60px" v-if="isShowChiefComplaint"/>
      <AppInfoItem label="电子病史" :txt="rowCurr.diseasesHistory" style="width: 100%;"/>
      <AppInfoItem label="临床诊断" :txt="rowCurr.clinicdiagnosis" style="width: 100%;"/>
      <AppInfoItem label="检查备注" v-if="!isSendParam" :txt="rowCurr.remarkInfo" style="width: 100%" item-txt-color="#f00">
        <i class="el-icon-edit" @click="editRemarkInfo(rowCurr.remarkInfo)" title="修改备注信息" style="cursor: pointer;color:#000" v-if="isSetRemarkInfo"></i>
      </AppInfoItem>
      <AppInfoItem label="检查目的" :txt="rowCurr.examPurpose" style="width: 100%"/>
      <AppInfoItem label="联系方式" v-if="isSendParam" :txt="rowCurr.patientPhone" style="width: 100%"><i class="el-icon-edit" @click="editPhone(rowCurr.patientPhone)" title="修改联系方式" style="cursor: pointer;"></i></AppInfoItem>
      <AppInfoItem label="金额" :txt="rowCurr.cost" style="width: 50%"/>
      <AppInfoItem label="收费状态" :txt="rowCurr.feeStatus" style="width: 50%"/>
      <AppInfoItem label="申请单号" :txt="rowCurr.applyCode" style="width: 100%"/>
    </div>
  </div>
</template>
<script>
import applyInfo from '@/mixin/applyInfo'
import bus from '@/api/bus'
import {
  getModalityList
} from '@/api/api'
export default {
  mixins: [applyInfo],
  props: {
    mipVisible: {
      type: Boolean,
      default: true
    },
    isConfigBedside: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isDev: process.env.NODE_ENV != 'production',
      isSendParam: window.g.isSendParam,
      // isSetEmergencyValue: this.$store.state.user.appSetting.isSetEmergencyValue,
      isShowEmergencyLimit: window.g.isShowEmergencyLimit,
      hBSagOptions: ['阴性', '阳性', '未检', '设置'],
      currentModality: '',
      defaultChoose: {
        hbsag: '阴性',
        hiv: '阴性',
        rpr: '阴性',
        hcv: '阴性',
        PRG: '阴性',
        SCR: '阴性'
      },
      checkcs: '',
      modalitylist: []
    }
  },
  watch: {
    'rowCurr.patientId': function (val) {
      if (val) {
        this.defaultChoose.hbsag = '阴性'
        this.defaultChoose.hiv = '阴性'
        this.defaultChoose.rpr = '阴性'
        this.defaultChoose.hcv = '阴性'
        this.defaultChoose.PRG = '阴性'
        this.defaultChoose.SCR = '阴性'
        this.isHbsag = false
        this.isHiv = false
        this.isHcv = false
        this.isRpr = false
        this.isPRG = false
        this.isSCR = false
      }
    },
    rowCurr: {
      handler(newVal, oldVal) {
        if (newVal.applyCode) {
          if (this.$store.state.settings.currentRow) {
            let currentRow = this.$store.state.settings.currentRow
            bus.$emit('changeListData', {
              row: currentRow,
              type: 'patModalityType',
              value: currentRow.value
            })
          }
          let hospCode = this.$store.state.user.hospitalCode
          this.getModality(newVal.dep, hospCode)
          this.currentModality = newVal.examClass
          let val = JSON.parse(JSON.stringify(newVal))
          this.$store.dispatch('settings/set_currentRow', {
            applyCode: val.applyCode,
            value: val.examClass
          })
        }
      }
    }
  },
  mounted() {
    this.getPrivacyLevel()
  },
  computed: {
    appConfig() {
      let appConfig = this.$store.state.settings.appConfig
      return appConfig
    },
    isToPrint() {
      return this.appConfig && this.appConfig.baseConfig && this.appConfig.baseConfig.isToPrint
    }
  },
  methods: {
    appointResultSearch() {
      this.$emit('appointResultSearch')
    },
    highlightedText(diseasesHistory) {
      if (diseasesHistory) {
        return diseasesHistory.replace(/(阳性)/g, '<span style="color: red;">$1</span>')
      } else {
        return null
      }
    },
    getModality(dep, hospCode) {
      const params = {
        HospitalCode: !hospCode ? this.mx_hospitalCode : hospCode,
        Dep: dep
      }
      this.modalitylist = []
      getModalityList(params).then(res => {
        if (res) {
          this.modalitylist = res.content.list
        } else {
          this.modalitylist = []
        }
      })
    }
  }
}
</script>

<style>
  .conditionSearchBtn{
    padding: 6px 8px !important;
  }
</style>

<style lang="scss" scoped>
  .pat_info{
    padding: 0 10px 10px;
    .pat_info_item{
      display: flex;
      flex-wrap: wrap;
    }
  }
  .pat_info .el-checkbox{
    margin-right: 11px;
  }
  .special-color >>> .el-input__inner {
      color: red !important;
  }
</style>
